package com.tools;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONPath;

import java.io.*;

/**
 * 读取文件中的json 进行解析
 * 解决String长度不足的问题
 */
public class JsonPathByFIle {
    public static String filePath = "C:\\Users\\yangjinlong\\Desktop\\jsonpath.txt";

 /*   public static void main(String[] args) {
        StringBuilder stringBuilder = new StringBuilder();
        BufferedReader fileReader = null;

        try {
            InputStreamReader inputStreamReader = new InputStreamReader(new FileInputStream(filePath), "GB2312");
            fileReader = new BufferedReader(inputStreamReader);

           *//*
           字节流读法
           每次读一个char数组   读到之后放进char数组里面 然后转成String
           如果读不到就是-1  读到了就没问题

           char[] chars = new char[1024];
            int len=0;
            while ((len = fileReader.read(chars)) != -1) {
                String s = new String(chars, 0, len);
                stringBuilder.append(s);
            }
            *//*
        *//*
          字符流读法  一行一行的读
          *//*
          String line ;
            while ((line=fileReader.readLine())!=null) {
                stringBuilder.append(line);
            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                fileReader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }


        JSONObject jsonObject = JSONObject.parseObject(stringBuilder.toString());

        Object eval = JSONPath.eval(jsonObject, "$.mainOfferOrderItems.accessProdOrderItems[prodInstId=\"-1\"]");

        System.out.println(eval);
    }*/
}
